// tsconfig.json
// const person: string = "TT";

// function  tt(name) {
//     return name
// }
// const tt2: string =  null;

interface Waiter {
  aj: boolean;
  say: () => {};
}
interface Teacher {
  aj: boolean;
  skill: () => {};
}

// function judge(anyOne: Waiter | Teacher) {
//   console.log(anyOne);
//   if (anyOne.aj) {
//     (anyOne as Teacher).skill();
//   } else {
//     (anyOne as Waiter).say();
//   }
// }

function judge2(anyOne: Waiter | Teacher) {
  // 类型守护
  if ("skill" in anyOne) {
    anyOne.skill();
  } else {
    anyOne.say();
  }
}

function add(first: string | number, second: string | number) {
  if (typeof first === "string" || typeof second === "string") {
    return `${first}${second}`;
  }
  return first + second;
}

class NumberObj {
  count: number;
}

function addObj(first: object | NumberObj, second: object | NumberObj) {
  if (first instanceof NumberObj && second instanceof NumberObj) {
    return first.count + second.count;
  }
  return 0;
}

let counts = addObj({count: 1}, {count: 2})
console.log(counts);
